package com.view.test.activity

import android.content.pm.ActivityInfo
import android.content.res.Configuration
import android.widget.TextView
import com.view.test.R
import com.view.test.base.KBaseActivity
import com.view.test.databinding.ActivityAllTestBinding
import com.yujing.utils.YPermissions
import com.yujing.utils.YUtils
import com.yujing.yview.GradingSoftKeyboard
import com.yujing.yview.GradingSoftKeyboardVertical
import com.yujing.yview.InputDialog
import com.yujing.yview.IpPort
import com.yujing.yview.NumberKeyboard
import com.yujing.yview.SetApiDialog
import com.yujing.yview.TestDialog
import com.yujing.yview.WebViewDialog
import com.yujing.yview.YSelectorDialog
import com.yujing.yview.YSetIpDialog
import com.yujing.yview.YTipsDialog
import com.yujing.yview.contract.YSuccessFailListener
import com.yutils.view.utils.Create

class MainActivity : KBaseActivity<ActivityAllTestBinding>(R.layout.activity_all_test) {
    lateinit var textView1: TextView
    override fun init() {
        YPermissions.requestAll(this)
        binding.wll.removeAllViews()
        binding.ll.removeAllViews()
        textView1 = Create.textView(binding.ll)

        Create.button(binding.wll, "退出测试APP") {
            finish()
        }

        Create.button(binding.wll, "空") {
            val dialog = TestDialog(this)
            dialog.show()
        }

        Create.button(binding.wll, "整数键盘") {
            val numberKeyboard = NumberKeyboard(this, false, NumberKeyboard.Type.INT)
            numberKeyboard.listener = { s -> textView1.text = s }
            numberKeyboard.textSizeScale = 1.0F
            numberKeyboard.show()
        }

        Create.button(binding.wll, "小数键盘") {
            NumberKeyboard(this, false, NumberKeyboard.Type.DOUBLE).apply {
                maxLength = 6
                listener = { s -> textView1.text = s }
                textSizeScale = 1.2F
                show()
            }
        }
        Create.button(binding.wll, "文本键盘") {
            val numberKeyboard = NumberKeyboard(this, false, NumberKeyboard.Type.STRING)
            numberKeyboard.listener = { s -> textView1.text = s }
            numberKeyboard.textSizeScale = 1.5F
            numberKeyboard.show()
        }
        Create.button(binding.wll, "密码键盘") {
            val numberKeyboard = NumberKeyboard(this, false, NumberKeyboard.Type.PASSWORD)
            numberKeyboard.listener = { s -> textView1.text = s }
            numberKeyboard.textSizeScale = 2.0F
            numberKeyboard.show()
        }
        Create.button(binding.wll, "身份证键盘") {
            val numberKeyboard = NumberKeyboard(this, false, NumberKeyboard.Type.IDCARD)
            numberKeyboard.listener = { s -> textView1.text = s }
            numberKeyboard.maxLength = 5
            numberKeyboard.hint="请输入身份证后5位"
            numberKeyboard.show()
        }
        Create.button(binding.wll, "自定义键盘") {
            val numberKeyboard = NumberKeyboard(this, false, NumberKeyboard.Type.STRING)
            numberKeyboard.listener = { s -> textView1.text = s }
            numberKeyboard.title="完全自定义键盘"
            numberKeyboard.names = arrayOf(
                "你", "好", "啊", "返回",
                "哈哈", "今天", "天气", "不错",
                "123", "456", "789", ".",
                "删除", "-", "确定"
            )
            numberKeyboard.inputKeYListener1 = { s ->
                if ("哈哈"==s){
                    YTipsDialog(this).apply {
                        title = "提示"
                        content = "哈哈"
                        btNameOK = "确定"
                        showCancelButton = false
                        setOnClickListener { dismiss() }
                        show()
                    }
                }
            }
            numberKeyboard.maxLength = 10
            numberKeyboard.hint="限制长度10"
            numberKeyboard.show()
        }

        Create.button(binding.wll, "提示") {
            YTipsDialog(this).apply {
                title = "通知"
                content = "这是一条提示消息!"
                btNameOK = "我知道了"
                showCancelButton = false
                setOnClickListener {
                    dismiss()
                    //确定逻辑
                }
                show()
            }
        }
        Create.button(binding.wll, "确定") {
            YTipsDialog(this, false, "提示", "是否确定？").apply {
                textSizeScale = 2.0f
                btNameOK = "确定"
                setOnClickListener {
                    dismiss()
                    //确定逻辑
                }
                btNameCancel = "取消"
                setCancelOnClickListener {
                    dismiss()
                    //取消取消
                }
                show()
            }
        }

        Create.button(binding.wll, "选择") {
            val name = arrayOf("全部", "1号线", "2号线", "3号线", "4号线", "5号线", "6号线", "7号线", "8号线", "9号线")
            val dialog = YSelectorDialog(this, *name)
            //dialog.textSizeScale=2.0f
            dialog.title = "请选择收购线"
            dialog.setOnValueListener { index, value ->
                dialog.dismiss()
                //逻辑操作
                showSpeak(name[index])
                textView1.text = name[index]
            }
            dialog.show()
        }

        Create.button(binding.wll, "定级软键盘") {
            if (this.resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT) {
                requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
            }
            GradingSoftKeyboard(this).apply {
                textSizeScale = 1.0F
                okListener = { grade, gradeName ->
                    dismiss()
                    //逻辑操作
                    showSpeak("$grade $gradeName")
                    textView1.text = "$grade $gradeName"
                }
                show()
            }
        }
        Create.button(binding.wll, "定级软键盘竖屏") {
            if (this.resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) {
                requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
            }
            val dialog = GradingSoftKeyboardVertical(this).apply {
                textSizeScale = 1.0F
                okListener = { grade, gradeName ->
                    dismiss()
                    //逻辑操作
                    showSpeak("$grade $gradeName")
                    textView1.text = "$grade $gradeName"
                }
                show()
            }
        }

        Create.button(binding.wll, "设置IP端口") {
            val dialog = YSetIpDialog(this)
            dialog.setYSuccessFailListener(object : YSuccessFailListener<IpPort?, String?> {
                override fun success(success: IpPort?) {
                    val ip = success?.Ip.toString()
                    val port = success?.Port.toString()
                    textView1.text = "您设置的IP是：$ip 端口是：$port"
                    showSpeak("您设置的I P是：$ip 端口是：$port")
                }

                override fun fail(fail: String?) {
                    fail?.let { showSpeak(it) }
                }
            })
            dialog.defaultIP = "192.168.6.9"
            dialog.defaultPort = "8080"
            dialog.show()
        }

        Create.button(binding.wll, "设置IP端口_软键盘") {
            val dialog = YSetIpDialog(this)
            dialog.textSizeScale = 2.0F
            dialog.uesNumberKeyboard = true
            dialog.setYSuccessFailListener(object : YSuccessFailListener<IpPort?, String?> {
                override fun success(success: IpPort?) {
                    val ip = success?.Ip.toString()
                    val port = success?.Port.toString()
                    textView1.text = "您设置的IP是：$ip 端口是：$port"
                    showSpeak("您设置的I P是：$ip 端口是：$port")
                }

                override fun fail(fail: String?) {
                    fail?.let { showSpeak(it) }
                }
            })
            dialog.defaultIP = "192.168.6.9"
            dialog.defaultPort = "8080"
            dialog.show()
        }

        Create.button(binding.wll, "设置URL端口") {
            val dialog = YSetIpDialog(this).apply {
                defaultIP = "http://www.baidu.com"
                defaultPort = "8080"
                type = 2
                setYSuccessFailListener(object : YSuccessFailListener<IpPort?, String?> {
                    override fun success(success: IpPort?) {
                        val ip = success?.Ip.toString()
                        val port = success?.Port.toString()
                        textView1.text = "您设置的地址是：$ip 端口是：$port"
                        showSpeak("您设置的地址是：$ip 端口是：$port")
                    }

                    override fun fail(fail: String?) {
                        fail?.let { showSpeak(it) }
                    }
                })
                show()
            }
        }

        Create.button(binding.wll, "设置API") {
            val dialog = SetApiDialog(this)
            dialog.textSizeScale = 1.0F
            dialog.setListener { api ->
                textView1.text = "API：$api"
                show("API：$api")
            }
            dialog.defaultApi = "http://192.168.1.109:8080/api/abc"
            dialog.show()
        }
        Create.button(binding.wll, "输入内容") {
            InputDialog(this).apply {
                textSizeScale = 2.0F
                maxLength = 10 //最大长度
                setListener { text ->
                    textView1.text = "内容：$text"
                }
                tvHide = "请输入内容"
                show()
            }
        }
        Create.space(binding.wll)
        Create.button(binding.wll, "Web_百度") {
            val dialog = WebViewDialog(this, "http://www.baidu.com", false)
            dialog.show()
        }

        Create.button(binding.wll, "Web_QQ") {
            val dialog = WebViewDialog(this, "http://www.qq.com", false)
            dialog.show()
        }
    }

    override fun onDestroy() {
        super.onDestroy()
        YUtils.exit()
    }
}






















